<template>
  <div class="photoinfo">
    <h3>{{info.title}}</h3>
    <p class="subtitle">
      <span>发表时间:{{info.add_time | dataFormat}}</span>
      <span>点击:{{info.click}}次</span>
    </p>
    <hr />
    <!-- 缩略图 -->
    <div class="thumbs">
      <vue-preview :slides="list"></vue-preview>
    </div>

    <!-- 内容区域 -->
    <div class="content" v-html="info.content"></div>

    <!-- 评论子组件 -->
    <comment :id="id"></comment>
  </div>
</template>

<script>
import comment from "../subcomponents/comment";
export default {
  data() {
    return {
      id: this.$route.params.id, //获取id
      info: [],
      list: [] //缩略图数组
    };
  },
  created() {
    this.Getinfo();
    this.GetPhoto();
  },
  methods: {
    Getinfo() {
      this.$ajax
        .request({
          url: "http://www.liulongbin.top:3005/api/getimageInfo/" + this.id,
          method: "GET"
        })
        .then(ret => {
          if (ret.data.status === 0) {
            this.info = ret.data.message[0];
          }
        });
    },
    GetPhoto() {
      this.$ajax
        .request({
          url: "http://www.liulongbin.top:3005/api/getthumimages/" + this.id,
          method: "GET"
        })
        .then(ret => {
          if (ret.data.status === 0) {
            // 循环每个图片数据,补全图片的宽和高
            ret.data.message.forEach(item => {
              item.w = 600;
              item.h = 400;
              item.msrc = item.src;
            });
            this.list = ret.data.message;
          }
        });
    }
  },
  components: {
    comment
  }
};
</script>

<style scoped>
.photoinfo {
  padding: 5px;
}
h3 {
  color: #26a2ff;
  text-align: center;
  margin: 15px 0;
}
.subtitle {
  display: flex;
  justify-content: space-between;
  font-size: 15px;
}
.content {
  font-size: 15px;
  line-height: 30px;
}
.thumbs .my-gallery {
    display: flex;
    flex-wrap: wrap;
}
.thumbs .my-gallery figure {
    width: 30%;
    margin: 5px;
}
</style>